package cn.com.chengmandian.bike.controller;


import cn.com.chengmandian.agent.utils.AuthUtil;
import cn.com.chengmandian.bike.dto.FaultBillInfoDto;
import cn.com.chengmandian.bike.dto.FaultBillInfoForm;
import cn.com.chengmandian.bike.dto.FaultBillInfoHandleForm;
import cn.com.chengmandian.bike.model.vo.FaultBillInfoVo;
import cn.com.chengmandian.bike.service.IEbFaultBillInfoService;
import cn.com.chengmandian.core.db.pojo.PageData;
import cn.com.chengmandian.core.web.pojo.AjaxResult;
import cn.com.chengmandian.core.web.utils.LocalMapUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 电单车运营-订单问题工单 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2024-05-29
 */
@Api(tags = "订单问题工单")
@RestController
@RequestMapping("/fault/bill/info")
public class EbFaultBillInfoController {

    @Autowired
    private IEbFaultBillInfoService faultBillInfoService;

    @ApiOperation("分页")
    @GetMapping("/page")
    public AjaxResult<PageData<FaultBillInfoVo>> pages(FaultBillInfoDto dto) {
        dto.setMemberId(AuthUtil.getAgentUser().getId());
        return AjaxResult.success(PageData.build(faultBillInfoService.getPage(dto)));
    }

    @ApiOperation("订单反馈列表")
    @GetMapping("/order/list")
    public AjaxResult<List<FaultBillInfoVo>> orderList(Integer orderId) {
        return AjaxResult.success(faultBillInfoService.getOrderList(orderId));
    }

    @ApiOperation("最近订单问题反馈")
    @GetMapping("/last/info")
    public AjaxResult<FaultBillInfoVo> lastInfo(Integer orderId) {
        return AjaxResult.success(faultBillInfoService.lastInfo(orderId));
    }

    @ApiOperation("详情")
    @GetMapping("/detail")
    public AjaxResult<FaultBillInfoVo> detail(Integer id) {
        return AjaxResult.success(faultBillInfoService.detail(id));
    }

    @ApiOperation("新增")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FaultBillInfoForm form) {
        Assert.notNull(form.getOrderId(), "缺少订单ID");
        Assert.notNull(form.getFaultType(), "缺少故障类型");

        faultBillInfoService.add(LocalMapUtil.getAgentInfo(), AuthUtil.getAgentUser(), form);
        return AjaxResult.success();
    }

    @ApiOperation("工单完结")
    @PostMapping("/complete")
    public AjaxResult complete(@RequestBody FaultBillInfoHandleForm form) {
        Assert.notNull(form.getId(), "缺少数据ID");

        faultBillInfoService.complete(form, LocalMapUtil.getAgentInfo(), AuthUtil.getAgentUser());
        return AjaxResult.success();
    }

    @ApiOperation("工单撤销")
    @PostMapping("/cancel")
    public AjaxResult cancel(@RequestBody FaultBillInfoHandleForm form) {
        Assert.notNull(form.getId(), "缺少数据ID");

        faultBillInfoService.cancel(form, LocalMapUtil.getAgentInfo(), AuthUtil.getAgentUser());
        return AjaxResult.success();
    }
}
